package cn.hnucm.pojo;

import cn.hnucm.bean.TbUserBasicMessage;
import cn.hnucm.vo.UserInfo;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @Author:liweihua
 * @Description:
 * @Date: 15:46$ 2021/12/18/018$
 * @Modified:
 */
@Data
public class User implements UserDetails {
    //用户id
    private int userId;
    //用户登录账号
    private String userAccount;
    //用户手机号码
    private String userMobile;
    //用户创建时间
    private String userCreateTime;
    //用户身份
    private String userIdentity;
    //用户昵称
    private String userUsername;
    //用户头像
    private String userHeadimageurl;
    //用户生日
    private String userBirthDatetime;
    private String userPassword;

    public void init(TbUserBasicMessage tbUserBasicMessage){
        this.userId = tbUserBasicMessage.getUserId();
        this.userAccount = tbUserBasicMessage.getUserAccount();
        this.userPassword = tbUserBasicMessage.getUserPassword();
        this.userMobile = tbUserBasicMessage.getUserMobile();
        this.userCreateTime = tbUserBasicMessage.getUserCreateTime();
        this.userIdentity = tbUserBasicMessage.getUserIdentity();
        this.userUsername = tbUserBasicMessage.getTbUserBasisList().get(0).getUserUsername();
        this.userHeadimageurl = tbUserBasicMessage.getTbUserBasisList().get(0).getUserHeadimageUrl();
        this.userBirthDatetime = tbUserBasicMessage.getTbUserBasisList().get(0).getUserBirthDatetime();
    }
    public UserInfo pull(){
        UserInfo userInfo = new UserInfo(this.userId,this.userAccount,this.userMobile,this.userCreateTime,this.userIdentity,
                this.userUsername,this.userHeadimageurl,this.userBirthDatetime);
        return userInfo;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.userPassword;
    }

    @Override
    public String getUsername() {
        return this.userAccount;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
